Page({
  data: {
    startX: 0,
    startY: 0
  },
  touchStart: function(e) {
    this.setData({
      startX: e.touches[0].x,
      startY: e.touches[0].y
    })
    this.context = wx.createCanvasContext('myCanvas')
    this.context.setStrokeStyle('#000')
    this.context.setLineWidth(5)
    this.context.setLineCap('round')
  },
  touchMove: function(e) {
    var startX = this.data.startX
    var startY = this.data.startY
    var endX = e.touches[0].x
    var endY = e.touches[0].y
    this.context.moveTo(startX, startY)
    this.context.lineTo(endX, endY)
    this.context.stroke()
    this.setData({
      startX: endX,
      startY: endY
    })
    this.context.draw(true)
  },
  touchEnd: function(e) {
    this.setData({
      startX: 0,
      startY: 0
    })
  },
  clearCanvas: function() {
    var that = this
    wx.showModal({
      title: '提示',
      content: '确定清空当前画板?',
      success: function(res) {
        if (res.confirm) {
          that.context.clearRect(0, 0, 700, 1000)
          that.context.draw(true)
        }
      }
    })
  },

  showLoading_function(types){
    let that = this;
    wx.showLoading({
      title: '加载中',
    })
    setTimeout(function () {
      wx.hideLoading()
      that.darwing_detect();
    }, 2000,)
  },

  darwing_detect(){
    let pinggugrade =  Math.floor(Math.random() * 16) + 15;
    wx.showModal({
      title: '帕金森患病率',
      content: pinggugrade + "%"
    })
  }
})